#include"ServerCal.hpp"
#include"TcpServer.hpp"
void Usage(const std::string &proc)
{
    std::cout<<"Usage:"<<proc<<"port\n"<<std::endl;
}
//./servercal 8080
int main(int argc,char*argv[])
{
    if(argc!=2)
    {
        Usage(argv[0]);
        exit(0);
    }
    uint16_t port=std::stoi(argv[1]);

    ServerCal cal;
    TcpServer*tsvp=new TcpServer(port,std::bind(&ServerCal::Calculator,&cal,std::placeholders::_1));
    tsvp->InitServer();
    tsvp->Start();
    /*  测试
    Response resp(1000,0);
    std::string content;
    resp.Serialize(&content);
    std::cout<<content<<std::endl;
    std::string package=Encode(content);
    std::cout<<package;

    content="";
    bool r=Decode(package,&content);
    std::cout<<content<<std::endl;

    Response tmp;
    tmp.Deserialize(content);
    std::cout<<tmp.code<<" "<<tmp.result<<std::endl;
    
    Request req(12345,45678,'+');
    std::string s;
    req.Serialize(&s);
    s=Encode(s);
    std::cout<<s;

    std::string content;
    bool r=Decode(s,&content);
    std::cout<<content<<std::endl;

    Request tmp;
    tmp.Deseralize(content);

    std::cout<<tmp.x<<" "<<tmp.op<<" "<<tmp.y<<std::endl;
    */
    return 0;
}